﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thinger.GenericTeach
{
    public delegate string DelegateTest(string data);
    class Program
    {
        static void Main(string[] args)
        {
            //Test1();
            //Test2();
            //Test3();
            Test4();

            Console.Read();
        }

        public static void Test1()
        {
            int size = 5;
            MyStack<int> myStack = new MyStack<int>(size);
            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);
            myStack.Push(4);
            myStack.Push(5);
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine(myStack.Pop());
            }

            MyStack<string> myStack2 = new MyStack<string>(size);
            myStack2.Push("string1");
            myStack2.Push("string2");
            myStack2.Push("string3");
            myStack2.Push("string4");
            myStack2.Push("string5");
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine(myStack2.Pop());
            }
        }

        static void Test2()
        {
            MyGenericClass2<int, string> myGenericClass1 = new MyGenericClass2<int, string>();
            MyGenericClass2<int, double> myGenericClass2 = new MyGenericClass2<int, double>();

        }


        static void Test3()
        {
            MyGenericClass1<int, Course, Teacher> myGenericClass = new MyGenericClass1<int, Course, Teacher>();

            myGenericClass.publisher = new Teacher() { Name = "常老师", CourseCount = 5 };

            myGenericClass.courseList = new List<Course>() {
                new Course() { CourseName = "课程1", Period = 3 },
                new Course() { CourseName = "课程2", Period = 4 },
                new Course() { CourseName = "课程3", Period = 5 },
                new Course() { CourseName = "课程4", Period = 6 },
                new Course() { CourseName = "课程5", Period = 7 }
            };

            var myCourse = myGenericClass.BuyCourse(1);
            Console.WriteLine($"我购买了课程：{myCourse.CourseName} 时间：{myCourse.Period} 个月  主讲老师：{myGenericClass.publisher.Name}");
        }


        static int Add1(int a,int b)
        {
            return a + b;
        }

        static double Add2(double a, double b)
        {
            return a + b;
        }

        static T Add3<T, T1, T2>(T1 a, T2 b) where T : struct, T1, T2
            //where T:struct
            //where T1:struct
            //where T2:struct
        {
            //return a + b;
            dynamic a1 = a;
            dynamic b1 = b;
            return a1 + b1;
        }

        static void Test4()
        {
            int c1 = Add3<int, int, int>(1, 2);
            double c2 = Add3<int, int, int>(1, 2);
            double c3 = Add3<double, double, double>(3.4, 4.5);
            Console.WriteLine(c1);
            Console.WriteLine(c2);
            Console.WriteLine(c3);
        }
        static DelegateTest delegateTest = null;
        static void Test5()
        {

            delegateTest = delegate (string data) 
            {
                return data;
            };

            delegateTest = (string data)=>
            {
                return data;
            };

            delegateTest = (data) =>
            {
                return data;
            };

            delegateTest = (data) => data;
        }
    }
}
